#pragma once
#include <strmif.h>

namespace VTSRead
{

class Sample : public IMediaSample
{
    Sample(IMemAllocator*);
    Sample(const Sample&);

    virtual ~Sample();
    
    Sample& operator=(const Sample&);

public:

    static Sample* CreateInstance(IMemAllocator*, const ALLOCATOR_PROPERTIES&);
    static void DestroyInstance(Sample*);    

    IMemAllocator* const m_allocator;        
    LONG m_refcount;        
    
    void init();
    
    HRESULT STDMETHODCALLTYPE QueryInterface(const IID&, void**);
    ULONG STDMETHODCALLTYPE AddRef();
    ULONG STDMETHODCALLTYPE Release();
    
    //IMediaSample interface:

    HRESULT STDMETHODCALLTYPE GetPointer( 
        BYTE** ppBuffer);
    
    long STDMETHODCALLTYPE GetSize();
    
    HRESULT STDMETHODCALLTYPE GetTime( 
        REFERENCE_TIME* pTimeStart,
        REFERENCE_TIME* pTimeEnd);
    
    HRESULT STDMETHODCALLTYPE SetTime( 
        REFERENCE_TIME* pTimeStart,
        REFERENCE_TIME* pTimeEnd);
    
    HRESULT STDMETHODCALLTYPE IsSyncPoint();
    
    HRESULT STDMETHODCALLTYPE SetSyncPoint( 
        BOOL bIsSyncPoint);
    
    HRESULT STDMETHODCALLTYPE IsPreroll();
    
    HRESULT STDMETHODCALLTYPE SetPreroll( 
        BOOL bIsPreroll);
    
    long STDMETHODCALLTYPE GetActualDataLength();
    
    HRESULT STDMETHODCALLTYPE SetActualDataLength(long);
    
    HRESULT STDMETHODCALLTYPE GetMediaType( 
        AM_MEDIA_TYPE** ppMediaType);
    
    HRESULT STDMETHODCALLTYPE SetMediaType( 
        AM_MEDIA_TYPE* pMediaType);
    
    HRESULT STDMETHODCALLTYPE IsDiscontinuity();
    
    HRESULT STDMETHODCALLTYPE SetDiscontinuity( 
        BOOL bDiscontinuity);
    
    HRESULT STDMETHODCALLTYPE GetMediaTime( 
        LONGLONG* pTimeStart,
        LONGLONG* pTimeEnd);
    
    HRESULT STDMETHODCALLTYPE SetMediaTime( 
        LONGLONG* pTimeStart,
        LONGLONG* pTimeStop);
        
private:

    bool m_sync_point;
    bool m_preroll;
    bool m_discontinuity;
    __int64 m_start_time;
    __int64 m_stop_time;
    __int64 m_media_start_time;
    __int64 m_media_stop_time;
    long m_actual_data_length;  //what portion of allocated memory holds actual data
    
    BYTE* m_buf;
    long m_buflen;  //how much memory was allocated 
    long m_off;     //to satisfy alignment requirements

};

}  //end namespace VTSRead
